using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using OR.Lazarus.Business;
using OR.Lazarus.Config;

namespace OR.Lazarus.Library.DataTier.Source
{
   public class ConstraintDetail : OR.Lazarus.Library.DataTier.Source.Lazarus.ConstraintDetail
   {
		public void Initialize()
		{
			this.SetDefaults();

			this.Validate();
		}

		public void SetDefaults()
		{
			if ( DataUtility.IsEmpty( mModifier ) )
			{
				mModifier = CompilerSettings.MODIFIERTYPE_DEFAULT;
			}
		}

		public void Validate()
		{
			if ( DataUtility.IsEmpty( mOperation ) )
			{
				throw new Exception( "Invalid Constraint: The [Operation] attribute is required." );
			}

			switch ( mOperation )
			{
				case CompilerSettings.OPERATIONTYPE_EQUAL:
				{
					if ( DataUtility.IsEmpty( mValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Equal] Operation requires the [Value] attribute." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_GREATERTHAN:
				{
					if ( DataUtility.IsEmpty( mMinValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Greater Than] Operation requires the [Min Value] attribute." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_GREATERTHANOREQUAL:
				{
					if ( DataUtility.IsEmpty( mMinValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Greater Than Or Equal] Operation requires the [Min Value] attribute." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_LESSTHAN:
				{
					if ( DataUtility.IsEmpty( mMaxValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Less Than] Operation requires the [Max Value] attribute." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_LESSTHANOREQUAL:
				{
					if ( DataUtility.IsEmpty( mMaxValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Less Than Or Equal] Operation requires the [Max Value] attribute." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_INCLUSIVEBETWEEN:
				{
					if ( DataUtility.IsEmpty( mMinValue ) || DataUtility.IsEmpty( mMaxValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Inclusive Between] Operation requires the [Min Value] and [Max Value] attributes." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_EXCLUSIVEBETWEEN:
				{
					if ( DataUtility.IsEmpty( mMinValue ) || DataUtility.IsEmpty( mMaxValue ) )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [Exclusive Between] Operation requires the [Min Value] and [Max Value] attributes." );
					}

					break;
				}
				case CompilerSettings.OPERATIONTYPE_IN:
				{
					if ( mValues.Count == 0 )
					{
						throw new ApplicationException( "ConstraintDetail.Validate() failed: The [In] Operation requires one or more entries in [Values] attributes." );
					}

					break;
				}
			}
		}
   }
}
   